package cn.cuilan.common.client;

import cn.cuilan.common.core.ConnectorConfiguration;

/**
 * 客户端配置信息类
 *
 * @author zhang.yan
 */
public class ClientConfiguration extends ConnectorConfiguration {

    /**
     * 默认客户端重新连接间隔（以毫秒为单位）
     */
    private static final int DEFAULT_RECONNECT_INTERVAL = 100;

    /**
     * 客户端重新连接间隔
     */
    private int reconnectInterval;

    public ClientConfiguration() {
        this(newBuilder());
    }

    public ClientConfiguration(ClientBuilder clientBuilder) {
        super(clientBuilder);
    }

    public static ClientBuilder newBuilder() {
        return new ClientConfiguration.ClientBuilder();
    }

    public static ClientConfiguration getDefault() {
        return newBuilder().build();
    }

    public int getReconnectInterval() {
        return reconnectInterval;
    }

    public void setReconnectInterval(int reconnectInterval) {
        this.reconnectInterval = reconnectInterval;
    }

    public static class ClientBuilder extends ConnectorConfiguration.Builder<ClientBuilder> {

        private int reconnectInterval = DEFAULT_RECONNECT_INTERVAL;

        public ClientBuilder reconnectInterval(int reconnectInterval) {
            this.reconnectInterval = reconnectInterval;
            return this;
        }

        public ClientBuilder withReconnectInterval(int reconnectInterval) {
            return reconnectInterval(reconnectInterval);
        }

        public ClientConfiguration build() {
            return new ClientConfiguration(this);
        }
    }
}
